handle upgrading repositories initialized with --version=9
authorJoey Hess <joeyh@joeyh.name>
Mon, 26 Sep 2022 16:55:51 +0000 (12:55 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 26 Sep 2022 16:59:51 +0000 (12:59 -0400)
As was attempted earlier in the buggy commit 0d2e3058ee01d55dc3b929ddf8e0573a95a2ca85

Avoided the bug that had by making the upgrade log be updated after each
upgrade step. So, after upgrade from v8 to v9, the log is updated, and
so Upgrade.V9's timeOfUpgrade check will find that it was upgraded
recently and so won't let it skip ahead to v10.

Sponsored-by: k0ld on Patreon
Upgrade.hs
Upgrade/V9.hs
doc/bugs/v8_repo_auto_upgrades_to_v10.mdwn
doc/bugs/v8_repo_auto_upgrades_to_v10/comment_1_446aa74f0b54918dc8737483e3e8564a._comment

index 2073b1bec085f1edd8c95bb70c89b2d51a3c2c92..244050444fe9839099baeba141658c0c85fd143e 100644 (file)
@@ -74,31 +74,24 @@ needsUpgrade v
                Left ex -> err $ "Automatic upgrade exception! " ++ show ex
 
 upgrade :: Bool -> RepoVersion -> Annex Bool
-upgrade automatic destversion = do
-       startversion <- getVersion
-       (ok, newversion) <- go startversion
-       when (ok && newversion /= startversion) $
-               postupgrade newversion
-       return ok
+upgrade automatic destversion = go =<< getVersion
   where
        go (Just v)
-               | v >= destversion = return (True, Just v)
+               | v >= destversion = return True
                | otherwise = ifM upgradingRemote
                        ( upgraderemote
                        , up v >>= \case
-                               UpgradeSuccess -> go (Just (incrversion v) )
-                               UpgradeFailed -> return (False, Just v)
-                               UpgradeDeferred -> return (True, Just v)
+                               UpgradeSuccess -> do
+                                       let v' = incrversion v
+                                       upgradedto v'
+                                       go (Just v')
+                               UpgradeFailed -> return False
+                               UpgradeDeferred -> return True
                        )
-       go Nothing = return (True, Nothing)
+       go Nothing = return True
 
        incrversion v = RepoVersion (fromRepoVersion v + 1)
 
-       postupgrade newversion = ifM upgradingRemote
-               ( reloadConfig
-               , maybe noop upgradedto newversion
-               )
-
 #ifndef mingw32_HOST_OS
        up (RepoVersion 0) = Upgrade.V0.upgrade
        up (RepoVersion 1) = Upgrade.V1.upgrade
@@ -121,15 +114,18 @@ upgrade automatic destversion = do
        -- upgrading a git repo other than the current repo.
        upgraderemote = do
                rp <- fromRawFilePath <$> fromRepo Git.repoPath
-               gitAnnexChildProcess "upgrade"
+               ok <- gitAnnexChildProcess "upgrade"
                        [ Param "--quiet"
                        , Param "--autoonly"
                        ]
                        (\p -> p { cwd = Just rp })
                        (\_ _ _ pid -> waitForProcess pid >>= return . \case
-                               ExitSuccess -> (True, Nothing)
-                               _ -> (False, Nothing)
+                               ExitSuccess -> True
+                               _ -> False
                        )
+               when ok
+                       reloadConfig
+               return ok
 
        upgradedto v = do
                setVersion v
index 124e285498ccb8da6c06949e8d7a4cd712ad638a..21c73fe5fb8b3a51b79760059e2c6fa9ba769d22 100644 (file)
@@ -40,12 +40,13 @@ upgrade automatic
         - and it is not safe for such to still be running after
         - this upgrade. -}
        oldprocessesdanger = timeOfUpgrade (RepoVersion 9) >>= \case
-               Nothing -> pure True
                Just t -> do
                        now <- liftIO getPOSIXTime
                        if now < t + 365*24*60*60
                                then return True
                                else assistantrunning
+               -- Initialized at v9, so no old process danger exists.
+               Nothing -> pure False
 
        {- Skip upgrade when git-annex assistant (or watch) is running,
         - because these are long-running daemons that could conceivably
index 023f8c694ce6f7805918665bf8542c506743fb5a..c9f294ed920c950462a57774d2f5360b67300259 100644 (file)
@@ -16,3 +16,4 @@ git config annex.version
 
 10.20220822 Linux
 
+> [[fixed|done]] --[[Joey]]
index 552276d45364f7208b400dfe111a8180513369cb..c9f786c0bd62b073610d650133092510ce7e6ad0 100644 (file)
@@ -8,7 +8,7 @@ which was included in version 10.20220822.
 
 I've reverted the commit as a first step. This means repos initialized
 at v9 will never autoupgrade to v10, which will need to be fixed
-somehow.
+somehow. (Update: Fixed that now.)
 
 Gonna need to make a git-annex release ASAP to get this fix out there.
 """]]